package br.com.vti.sisp_sicrim.antigo.controller.relatorios;

import java.io.FileNotFoundException;
import java.text.ParseException;

import net.sf.jasperreports.engine.JRException;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.interceptor.download.InputStreamDownload;
import br.com.vti.sisp_sicrim.antigo.model.SicTabelas;
import br.com.vti.sisp_sicrim.antigo.model.Sislac01;
import br.com.vti.sisp_sicrim.antigo.model.Sisll001;
import br.com.vti.sisp_sicrim.antigo.util.Relatorios;
import br.com.vti.sisp_sicrim.antigo.util.Sessao;
import br.com.vti.sisp_sicrim.antigo.util.UtilBean;

/**
 * Classe responsavel por encapsular o tratamento e as consistencias da tela
 * Tabpe006Report
 * 
 * @author Incode - Data: mai/2014
 * 
 */
public class Tabpe006Report {
	private String nomeClasse;
	private String fg;
	private String valor;
	private double vlu;
	private String cabecaSeg;
	private String cabecaDet;
	private int dataCorrente;
	private Long dintabCodele; // DB
	public String codele;
	public String val;
	public String cd;
	private String nroPagina;
	private Result result;
	private Sessao sessao;
	private Relatorios report;
	// Classes views
	SicTabelas vwDvetab = new SicTabelas();
	SicTabelas vwTabele = new SicTabelas();
	// Classes includes
	Sislac01 sislac01 = new Sislac01();
	Sisll001 sisll001 = new Sisll001();

	public Tabpe006Report() throws JRException, ParseException {
		inicializar();
	}

	public Tabpe006Report(Sessao sessao) throws JRException, ParseException {
		this.sessao = sessao;
		inicializar();
	}

	public void inicializar() throws JRException, ParseException {
		report = new Relatorios();
		fg = "";
		vlu = 0;
		cabecaSeg = "SECRETARIA DE ESTADO DA SEGURAN�A PUBLICA";
		cabecaDet = "SECRETARIA ADJUNTA DE TECNOLOGIA DA INFORMACAO - SEATI";
		dataCorrente = 0;
		nomeClasse = this.getClass().getSimpleName(); // *PROGRAM
		report.setNumeroRel(1, "C");
		{
			report.setNumeroLinhaRel(1, 1);
			{
				report.adicionaCampo(1, 1, "lit_1_1", "C", "", " ");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(2, 3);
			{
				report.adicionaCampo(2, 60, "Cabecaseg", "X", "ZZ99", "");
				report.adicionaCampo(72, 3, "lit_72_3", "C", "", "PAG");
				report.adicionaCampo(76, 5, "nroPagina", "S", "ZZ99", "");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(3, 2);
			{
				report.adicionaCampo(2, 60, "Cabecadet", "X", "", "");
				report.adicionaCampo(72, 8, "lit_72_8", "C", "", "TABPE006");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(4, 2);
			{
				report.adicionaCampo(2, 42, "lit_2_42", "C", "", "CADASTRO DE APOIO ==> TABELA VALOR DE IPVA");
				report.adicionaCampo(72, 8, "dataCorrente", "N", "", "");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(5, 1);
			{
				report.adicionaCampo(1, 1, "lit_1_1", "C", "", "-");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(6, 4);
			{
				report.adicionaCampo(2, 12, "lit_2_12", "C", "", "ANO/COD MOD.");
				report.adicionaCampo(17, 12, "lit_17_12", "C", "", "MARCA/MODELO");
				report.adicionaCampo(47, 13, "lit_47_13", "C", "", "VALOR EM REAL");
				report.adicionaCampo(69, 9, "lit_69_9", "C", "", "QDE. UFIR");
				report.setFimLinhaRel();
			}
		}
		report.setNumeroRel(2, "D");
		{
			report.setNumeroLinhaRel(1, 4);
			{
				report.adicionaCampo(1, 12, "Dintabcodele", "N", "ZZ99/99/999999", "");
				report.adicionaCampo(17, 28, "Fg", "X", "ZZ99/99/999999", "");
				report.adicionaCampo(47, 9, "Valor", "N", "ZZZ.ZZZ.ZZ9,99", "");
				report.adicionaCampo(69, 6, "Vlu", "N", "ZZZ.ZZ9,99", "");
				report.setFimLinhaRel();
			}
		}
		setCabecaseg(cabecaSeg);
		setCabecadet(cabecaDet);
	}

	public boolean validar() {
		// validar os campos recebidos da tela
		return true;
	}

	public String getFg() {
		return fg;
	}

	public void setFg(String fg) throws ParseException {
		this.fg = fg;
		report.adicionaValorReport("Fg", fg);
	}

	public String getValor() {
		return valor;
	}

	public void setValor(String valor) throws ParseException {
		this.valor = valor;
		report.adicionaValorReport("Valor", valor);
	}

	public double getVlu() {
		return vlu;
	}

	public void setVlu(double vlu) throws ParseException {
		this.vlu = vlu;
		report.adicionaValorReport("Vlu", vlu);
	}

	public String getCabecaseg() {
		return cabecaSeg;
	}

	public void setCabecaseg(String cabecaSeg) throws ParseException {
		this.cabecaSeg = cabecaSeg;
		report.adicionaValorReport("Cabecaseg", cabecaSeg);
	}

	public String getCabecadet() {
		return cabecaDet;
	}

	public void setCabecadet(String cabecaDet) throws ParseException {
		this.cabecaDet = cabecaDet;
		report.adicionaValorReport("Cabecadet", cabecaDet);
	}

	public int getDataCorrente() {
		return dataCorrente;
	}

	public void setDataCorrente(int dataCorrente) throws ParseException {
		this.dataCorrente = dataCorrente;
		report.adicionaValorReport("dataCorrente", dataCorrente);
	} // /

	public String getCodele() {
		return this.cd;
	}

	public void setCodele(String codele) throws ParseException {
		this.codele = codele;
		this.cd = UtilBean.subStr(codele, 0, 6);
		report.adicionaValorReport("Cd", UtilBean.subStr(codele, 0, 6));
	} // /

	public String getVal() {
		return this.valor;
	}

	public void setVal(String val) throws ParseException {
		this.val = val;
		this.valor = UtilBean.subStr(val, 0, 9);
		report.adicionaValorReport("Valor", UtilBean.subStr(val, 0, 9));
	}

	public String getNomeClasse() {
		return nomeClasse;
	}

	public void setNomeClasse(String nomeClasse) throws ParseException {
		this.nomeClasse = nomeClasse;
		report.adicionaValorReport("nomeClasse", nomeClasse);
	}

	public String getNroPagina() {
		return nroPagina;
	}

	public void setNroPagina(String nroPagina) throws ParseException {
		this.nroPagina = nroPagina;
		report.adicionaValorReport("nroPagina", nroPagina);
	}

	public void setPageSize(int pagesize) throws JRException {
		report.setPageSize(pagesize);
	}

	public void setLineSize(int linesize) {
		report.setLineSize(linesize);
	}

	public int getPageSize() {
		return report.getPageSize();
	}

	public int getPageLine() {
		return report.getPageLine();
	}

	public void saltaLinhas(int qtdLinhas) throws ParseException, JRException {
		report.saltaLinhas(qtdLinhas);
	}

	public void gravaRelatorio(int nroRel) throws ParseException, JRException {
		setNroPagina(String.valueOf(report.getPageNumber()));
		report.gravaRelatorio(report, nroRel, false);
	}

	public InputStreamDownload imprimir() throws FileNotFoundException, JRException {
		return report.imprimir();
	}

	public Long getDintabCodele() {
		return dintabCodele;
	}

	public void setDintabCodele(Long dintabCodele) throws ParseException {
		this.dintabCodele = dintabCodele;
		report.adicionaValorReport("dintabCodele", dintabCodele);
	}

}
